package com.pan.studentmaster;

import java.io.IOException;
import java.io.InputStream;

import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class CourseActivity extends GridActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public Cursor getCursor() {
		return DB.instance().getCourses();
	}

	@Override
	public BitmapDrawable getDrawable(Cursor cursor) {
		String name = cursor.getString(cursor.getColumnIndex(DB.COURSE._NAME));
		try {
			InputStream is = getResources().getAssets().open(name + ".jpg");
			BitmapDrawable drawable = new BitmapDrawable(getResources(), is);
			return drawable;
		}
		catch(IOException e) {
			Log.e("Course", "No thumbnail image " + name + ".jpg in assets");
			return null;
		}
	}

	@Override
	public void onItemClick(View v) {
		int course = v.getId();
		Intent i = new Intent().setClass(this, BookActivity.class);
		i.putExtra("COURSE", course);
		startActivity(i);
	}

}
